package com.stud.seckill.controller;

import com.stud.seckill.entity.vo.OrderDetailVo;
import com.stud.seckill.common.vo.R;
import com.stud.seckill.entity.GoodsEntity;
import com.stud.seckill.entity.OrderEntity;
import com.stud.seckill.service.GoodsService;
import com.stud.seckill.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Libra
 * @since 2024-03-30
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/detail")
    public R<OrderDetailVo> getDetail(@RequestParam Long orderId) {

        OrderDetailVo orderDetailVo = new OrderDetailVo();

        OrderEntity orderEntity = orderService.get(orderId);
        GoodsEntity goodsEntity = goodsService.get(orderEntity.getGoodsId());

        orderDetailVo.setOrder(orderEntity);
        orderDetailVo.setGoodsVo(goodsEntity);

        return R.success(orderDetailVo);
    }

}
